﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace parkour.Classes
{
   /// <summary>
   /// Class for holding the registration info
   /// </summary>
   public class clsRegistrationInfo
   {
      #region Variables

      private int vehicle_type;              // The vehicle type
      private int model_ID;                  // The vehicle model ID; the make is not needed becase we can determine the make from the model
      private int color_ID;                  // The vehicle color ID
      private int parking_spot;              // The spot where the vehicle will be parked
      private int automobile_size_ID;        // The automobile size ID

      private string user_ID;                // The user's ID or username
      private string department;             // The department type
      private string auto_year;              // The automobile year
      private string license_number;         // The license plate number
      private string registration_state;     // The registration state
      private string insurance_company;      // The insurance company
      private string seatbelt_number;        // The number of seatbelts

      private DateTime registration_date;    // The time of vehicle registration

      private const int TYPE_AUTOMOBILE = 1; // Type that identifies an automobile
      private const int TYPE_MOTORCYCLE = 2; // Type that identifies a motorcycle
      private const int TYPE_SEGWAY     = 3; // Type that identifies a segway
      private const int TYPE_GOLFCART   = 4; // Type that identifies a golf cart

      #endregion

      #region Properties

      /// <summary>
      /// Get and set property for the vehicle type
      /// </summary>
      public int type_of_vehicle
      {
         get
         {
            return vehicle_type;
         }
         set
         {
            vehicle_type = value;
         }
      }

      /// <summary>
      /// Get and set property for the model type
      /// </summary>
      public int model
      {
         get
         {
            return model_ID;
         }
         set
         {
            model_ID = value;
         }
      }

      /// <summary>
      /// Get and set property for the color
      /// </summary>
      public int color
      {
         get
         {
            return color_ID;
         }
         set
         {
            color_ID = value;
         }
      }

      /// <summary>
      /// Get and set property for the department type
      /// </summary>
      public string department_type
      {
         get
         {
            return department;
         }
         set
         {
            department = value;
         }
      }

      /// <summary>
      /// Get and set property for the automobile year
      /// </summary>
      public string automobile_year
      {
         get
         {
            return auto_year;
         }
         set
         {
            auto_year = value;
         }
      }

      /// <summary>
      /// Get and set property for license plate number
      /// </summary>
      public string license_plate
      {
         get
         {
            return license_number;
         }
         set
         {
            license_number = value;
         }
      }

      /// <summary>
      /// Get and set property for registration state
      /// </summary>
      public string state
      {
         get
         {
            return registration_state;
         }
         set
         {
            registration_state = value;
         }
      }

      /// <summary>
      /// Get and set property for the insurance company
      /// </summary>
      public string insurance
      {
         get
         {
            return insurance_company;
         }
         set
         {
            insurance_company = value;
         }
      }

      /// <summary>
      /// Get and set property for the seatbelt number
      /// </summary>
      public string seatbelts
      {
         get
         {
            return seatbelt_number;
         }
         set
         {
            seatbelt_number = value;
         }
      }

      /// <summary>
      /// Gets or sets the parking spot for a vehicle
      /// </summary>
      public int vehicle_parking_spot_ID
      {
         get
         {
            return parking_spot;
         }

         set
         {
            parking_spot = value;
         }
      }

      /// <summary>
      /// Get and set property for the username
      /// </summary>
      public string username
      {
         get
         {
            return user_ID;
         }
         set
         {
            user_ID = value;
         }
      }

      /// <summary>
      /// Get and set property for the automobile size
      /// </summary>
      public int automobile_size
      {
         get
         {
            return automobile_size_ID;
         }
         set
         {
            automobile_size_ID = value;
         }
      }

      /// <summary>
      /// Get and set property for the date and time of registration
      /// </summary>
      public DateTime time_of_registration
      {
         get
         {
            return registration_date;
         }
         set
         {
            registration_date = value;
         }
      }

      #endregion

      #region Functions

      /// <Page load>
      /// Page load initialization
      /// </Page load>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      protected void Page_Load(object sender, EventArgs e)
      {

      }

      /// <Register a vehicle>
      /// Register a vehicle by pushing the info to the database
      /// </Register a vehicle>
      public void register_vehicle()
      {
         int successfully_registered;      // Indicates if the vehicle was successfully registered
         SqlConnection DataBaseConnection; // The connection for using the database
         SqlCommand register_user_vehicle;    // The command for registering a vehicle

         // Open DB connection
         DataBaseConnection = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SEI_PKConnString"].ConnectionString);
         DataBaseConnection.Open();

         // Register the different types of vehicles
         switch (vehicle_type)
         {
            case TYPE_AUTOMOBILE:
               // Load stored procedure and add parameters
               register_user_vehicle = new SqlCommand("register_automobile", DataBaseConnection);
               register_user_vehicle.CommandType = CommandType.StoredProcedure;
               //register_user_vehicle.Parameters.AddWithValue("@user_ID", UserID.Text);
               register_user_vehicle.Parameters.AddWithValue("@registration_date", registration_date);
               register_user_vehicle.Parameters.AddWithValue("@type_ID", vehicle_type);
               register_user_vehicle.Parameters.AddWithValue("@model_ID", model_ID);
               register_user_vehicle.Parameters.AddWithValue("@parking_spot_ID", parking_spot);
               register_user_vehicle.Parameters.AddWithValue("@department_ID", department);
               register_user_vehicle.Parameters.AddWithValue("@status_flag_ID", 1);  // This needs to know what the correct value is 
               register_user_vehicle.Parameters.AddWithValue("@vehicle_ID", 113); // What is this?
               register_user_vehicle.Parameters.AddWithValue("@color", color_ID);
               register_user_vehicle.Parameters.AddWithValue("@year", auto_year);
               register_user_vehicle.Parameters.AddWithValue("@seatbelt", seatbelt_number);
               register_user_vehicle.Parameters.AddWithValue("@license_number", license_number);
               register_user_vehicle.Parameters.AddWithValue("@registration_state", registration_state);
               register_user_vehicle.Parameters.AddWithValue("@insurance_ID", insurance_company);
               register_user_vehicle.Parameters.AddWithValue("@automobile_size_ID", automobile_size_ID);
               break;

            case TYPE_MOTORCYCLE:
               //// Load stored procedure and add parameters
               //register_user_vehicle = new SqlCommand("register_automobile", DataBaseConnection);
               //register_user_vehicle.CommandType = CommandType.StoredProcedure;
               //register_user_vehicle.Parameters.AddWithValue("@user_ID", UserID.Text);
               //break;

            case TYPE_GOLFCART:
               //// Load stored procedure and add parameters
               //register_user_vehicle = new SqlCommand("register_automobile", DataBaseConnection);
               //register_user_vehicle.CommandType = CommandType.StoredProcedure;
               //register_user_vehicle.Parameters.AddWithValue("@user_ID", UserID.Text);
               //break;

            case TYPE_SEGWAY:
               //// Load stored procedure and add parameters
               //register_user_vehicle = new SqlCommand("register_automobile", DataBaseConnection);
               //register_user_vehicle.CommandType = CommandType.StoredProcedure;
               //register_user_vehicle.Parameters.AddWithValue("@user_ID", UserID.Text);
               //break;

            default:
               break;
         }

         //Execute SQL statement and dispose
         //successfully_registered = register_user_vehicle.ExecuteNonQuery();
         //register_user_vehicle.Dispose();

         //if (successfully_registered == 1)
         //{

         //}
         //else
         //{
         //   //register failed
         //}

         // Close DB connection
         DataBaseConnection.Close();
         DataBaseConnection.Dispose();
               
      }

      /// <Reserve parking spot>
      /// Reserve a parking spot
      /// </summary>
      public Boolean reserve_parking_spot()
      {
         return false;
      }

      #endregion

      #region Events
      #endregion
   }
}